package com.redpacketcover.rc.base;


import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Java Fragment公用基类
 */

public abstract class BasicFragment<P extends BasicIPresenter> extends Fragment implements BasicView {

    private View mContentView = null;
    public Activity mActivity = null;
    protected Unbinder mUnBinder;

    protected P mPresenter;

    protected abstract void initViews(View view);  // 初始化view

    protected abstract void initData();//初始化

    protected abstract int initLayout();//设置布局

    protected abstract P createPresenter();//MVP模式重写这个方法，如果是简单的页面不用MVP模式忽略此方法即可

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        mActivity = activity;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mContentView = inflater.inflate(initLayout(), container, false);
        mUnBinder = ButterKnife.bind(this, mContentView);
        mPresenter = createPresenter();
        if (mPresenter != null) {
            mPresenter.attachView(this);
        }
        initViews(mContentView);
        initData();
        return mContentView;
    }


}
